#include "slist.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void my_destroy(void *data);

void my_printf(void *data);

int main(int argc, char **argv)
{
    slist_t *s = NULL;
    int num = 0;

    // 创建
    slist_create(&s, sizeof(int), my_destroy);

    while (1)
    {
    op:
        my_scanf(op, "%d", &num);

        if (-1 == num)
        {
            break;
        }

        //slist_append(s, &num);
        slist_prepend(s, &num);
    }
    slist_traverse(s, my_printf);
    num = 66;
    slist_insert_by_index(s, &num, 3);
    slist_traverse(s, my_printf);

    slist_delete_by_index(s, s->count, my_destroy);

    // 遍历
    slist_traverse(s, my_printf);


    // 销毁
    slist_destory(s);

    free(s);
    s = NULL;


    return 0;
}



void my_destroy(void *data)
{
    node_t *tmp = NULL;

    // 参数检查
    if (NULL == data)
    {
        perror("argument lawless...");
        return;
    }

    tmp = data;

    free(tmp->data);
    tmp->data = NULL;
    free(tmp);
    tmp = NULL;

    return;
}


void my_printf(void *data)
{
    node_t *tmp = NULL;
    // 参数检查
    if(NULL == data)
    {
        perror("argument lawless...");
        return;
    }

    tmp = data;

    printf("%d ", *((int *)tmp->data));


    return;
}